﻿Chenxin.UI.PgSalePaymentsBalance = Chenxin.extend(Chenxin.UI.PageCommon, {
    autoInitForm: false,
    actionUrl: '/service/logic/SalePaymentsBalance.ashx',
    createSearch: function() {
        return new Chenxin.UI.SrhSalePaymentsBalance({
            scope: this
        });
    },
	exportAll:function(){
	    _this = this;
	    paramStr = this.search.getParamJson();
	    paramStr.op = 'exportAll';
	    Chenxin.Msg.Waiting.show();
	    Chenxin.Fn.exportToExcelByServer(this.actionUrl, paramStr, '导出文件');
	    //$.ajax({ url: this.actionUrl, data: paramStr,async:false});
	    Chenxin.Msg.Waiting.hide();
	},
    createGrid:function(){
		_this = this;
        return new Chenxin.UI.ReportGrid({
			createTitleTool:function(){					
				return [{
					text: '<span id="" class="x-grid-export" style="width:90px" title="导出全部数据">导出全部数据</span>',
					scope:this,
					title:'导出全部数据',
					handler:function(el){
						_this.exportAll();
					}
				}];
			},
            actionUrl: this.actionUrl + '?op=search',
            pageSize: 100,
            height: 400,
            hasTotal: false,
            renderTo: 'divShowBalanceList',
            hasCheckBox: false,
            scope: this,
            autoLoad: false,
			hasPage: true,
            id: 'BalanceList',
            title: '房款收支平衡表',
            scope: this,
            columns: {
                AreaName: {
                    width: 122,
                    head: "商圈",
                    sortable: true,
                    inTotal: false,
					captionCol:true
                },
                Depart: {
                    width: 180,
                    head: "部门",
                    sortable: true,
                    inTotal: false
                },
                UserName: {
                    width: 100,
                    head: "业务员",
                    sortable: true,
                    inTotal: false
                },
                ContractCode: {
                    width: 140,
                    head: "成交编号",
                    sortable: true,
                    inTotal: false
                },
                ContractDate:{
                    width:80,
                    head:"成交日期",
                    sortable: true,
                    inTotal: false
                },
                VenderName: {
                    width: 140,
                    head: "上家客户姓名",
                    sortable: true,
                    inTotal: false
                },
                BuyerName: {
                    width: 140,
                    head: "下家客户姓名",
                    sortable: true,
                    inTotal: false
                },
                HouseAddress: {
                    width: 300,
                    head: "房源地址",
                    sortable: true,
                    inTotal: false
                },
                Area: {
                    width: 80,
                    head: "建筑面积",
                    sortable: true,
					style: 'text-align:right',
                    inTotal: false
                },
                BargainPrice: {
                    width: 80,
                    head: "合同标的",
                    sortable: true,
					style: 'text-align:right',
                    inTotal: false
                },
                CanGetSaleMoney: {
                    width: 80,
                    head: "应收房款",
					style: 'text-align:right',
                    sortable: true
                },
                GetedSaleMoney: {
                    width: 80,
                    head: "总收取房款",
					style: 'text-align:right',
                    sortable: true
                },
                PayedSaleMoney: {
                    width: 80,
                    head: "总支付房款",
					style: 'text-align:right',
                    sortable: true
                },
                RemainSaleMoney: {
                    width: 80,
                    head: "未付房款",
					style: 'text-align:right',
                    sortable: true
                }
            }
        });
    },
    initComponent: function() {
        Chenxin.UI.PgSalePaymentsBalance.superclass.initComponent.call(this);
        //this.searchGrid();
    }
});

/*
* 查询面板
*/
Chenxin.UI.SrhSalePaymentsBalance = Chenxin.extend(Chenxin.UI.SearchCommon, {
    id: 'divCondition',
    createComboList: function() {
        //日期类型
        var cmbDateType = new Chenxin.UI.Combo({
            containerId: '#DateType',
            tbxWidth: 45,
            addPleaseSelected: false,
            items: comboCommon.BalanceDateType
        });

        //收支情况
        var cmbBalanceStatus = new Chenxin.UI.Combo({
            containerId: '#BalanceStatus',
            tbxWidth: 45,
            items: comboCommon.BalanceStatus
        });
        
        var combl = new Chenxin.UI.StructComboList();
        var structs = combl.comboList;
        structs.push(cmbDateType);
        structs.push(cmbBalanceStatus);

        return structs;
    },
    initEvent: function() {
        var curdate = new Date();
        $('#txtStartTime').val(curdate.getFullYear() + '-' + (curdate.getMonth() + 1) + '-1');
        if (curdate.getMonth() + 1 == 12)
            $('#txtEndTime').val(curdate.getFullYear() + 1 + '-1-1');
        else
            $('#txtEndTime').val(curdate.getFullYear() + '-' + (curdate.getMonth() + 2) + '-1');
        
        $("#txtStartTime").focus(function() {
            WdatePicker({
                dateFmt: 'yyyy-MM-dd',
                oncleared: function() {
                    $(this).blur();
                },
                onpicked: function() {
                    $(this).blur();
                }
            });
        });

        $("#txtEndTime").focus(function() {
            WdatePicker({
                dateFmt: 'yyyy-MM-dd',
                oncleared: function() {
                    $(this).blur();
                },
                onpicked: function() {
                    $(this).blur();
                }
            });
        });

        $("#txtKeyword").defText({
            deftxt: '成交编号/房源地址'
        });

        var objSrh = this;
        /*********事件：检索按钮*********/
        $("#btSearch").click(function() {
            objSrh.scope.searchGrid();
        });
    }
});

getcity = true; //设置需要获取城市下拉框数据

$(function() {
    var objPg = new Chenxin.UI.PgSalePaymentsBalance();
});